package com.example.baselibrary.utlis;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

public class ActivityCollector {

    private static List<Activity> activities = new ArrayList<>();

    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    public static void removeActivity(Activity activity) {
        if (activities.contains(activity)) {
            activities.remove(activity);
        }
    }

    public static void finishAll() {
        for (int i = 0; i < activities.size(); i++) {
            if (!activities.get(i).isFinishing()) {
                activities.get(i).finish();
            }
            activities.clear();
        }
    }

    public static boolean isLastActivity() {
        if (activities.size() == 1) {
            return true;
        } else {
            return false;
        }

    }


}
